<?php 
include "method/win.php";

if(!isset($_SESSION['user'])){
    show_msg("请先登录!","login.php");
}
if(isset($_GET['action'])){
    logout();
}
if(isset($_GET['id'])){
    $comsql = "select weibo_comment.*, weibo_user.* from weibo_comment, weibo_user where weibo_comment.cm_author=weibo_user.user_name and weibo_comment.cm_id='".$_GET['id']."'";
}else {
    $comsql = "select weibo_comment.*, weibo_user.* from weibo_comment, weibo_user where weibo_comment.cm_author=weibo_user.user_name limit 1";
}
$comres = $conn->query($comsql);
$comrow = $comres->fetch_assoc();
$defsql = "select * from weibo_kidcomment where cm_id='".$comrow['cm_id']."' order by kidcm_time desc";
$defres = $conn->query($defsql);
if(isset($_POST['submit'])){
    addkidcm($_POST['kcm_tx'], date("Y-m-d H:i:s"), $comrow['cm_id'], $comrow['weibo_id']);
//     show_msg("回复成功", "kid_comment.php?id=".$comrow['cm_id']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>评论回复</title>
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/kid_comment.css">
    <script src="../lib/jquery/jquery.js" type="text/javascript"></script>
    <script src="../lib/bootstrap/js/bootstrap.js" type="text/javascript"></script>
</head>
<body style=background-image:url("../img/kid-bg.jpg")>
<!--顶部导航条-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!--头部logo-->
        <div class="navbar-header">
            <a class="navbar-brand" href="#"><em><img src="../img/logo.jpg" height=30 width=30></em><em>小狗微博</em></a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!--搜索框-->
            <form class="navbar-form navbar-left" role="search" method="post" action="search_loginafter.php">
                <div class="form-group">
                    <input type="text" class="form-control" style="width: 400px" placeholder="Search" name="str-search">
                </div>
                <button type="sumbit" class="btn btn-default" name="search-btn">搜索</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="index_loginafter.php">首页</a></li>
                <li><a href="person_loginafter.php"><?php echo $_SESSION['user']?></a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">我的消息 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="inbox.php?page=1">@我</a></li>
                        <li><a href="inbox.php?page=2">评论</a></li>
                        <li><a href="inbox.php?page=3">回复</a></li>
                        <li><a href="inbox.php?page=4">赞</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">个人中心 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                    	<li><a href="fixpw.php">修改密码</a></li>
                        <li><a href="fixtx.php">修改头像</a></li>
                        <li><a href="index_loginafter.php?action=logout">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!--版心-->
<div class="warp clearfix">
    <!--左边版心-->
    <div class="left-warp">
        <!--父评论-->
        <div class="comment-parent clearfix">
            <!--父头像-->
            <div class="parent-tx">
                <img src="../<?php echo $comrow['user_tx']?>" style="width: 30px; height: 30px">
            </div>
            <!--父评论主体-->
            <div class="pcomment-content">
                <!--父评论内容-->
                <div class="pcomment-txt">
                    <a href="#"><?php echo $comrow['user_name']?>：</a><?php echo $comrow['cm_content']?>
                </div>
                <!--父评论时间-->
                <div class="pcomment-time"><?php echo $comrow['cm_time']?></div>
                <!--子评论列表-->
                <div class="kcomment-list">
                    <!--评论操作框-->
                    <div class="comment-op clearfix">
                        <form action="" method="post" onsubmit="return checkNull()">
                            <textarea id="kid-comment" rows="1" name="kcm_tx"></textarea>
                            <button type="submit" name="submit">回复</button>
                        </form>
                    </div>
					
					<?php 
					if($defres->num_rows){
					    while ($rows = $defres->fetch_assoc()){
// 					        子评论盒子
					        echo "<div class='kcoment-box'>";
// 					        子评论内容
					        echo "<div class='kcomment-txt'>";
					        echo "<a href='#'>".$rows['kidcm_author'].":</a>".$rows['kidcm_content']."</div>";
// 					        子评论时间
					        echo "<div class='kcomment-time'>".$rows['kidcm_time']."";
					        if($rows['kidcm_author']==$_SESSION['user']){
					            echo "<span><a href='javascript:' onclick=delKidCm(".$rows['kidcm_id'].")>删除</a></span>";
					        }else{
					            echo "<span><a href='javascript:' onclick=comKidCm(".$rows['kidcm_id'].")>投诉</a></span>";
					        }
					        echo "</div></div>";
					    }
					}
					?>
                    
                </div>

            </div>
        </div>
    </div>

    <!--右边版心-->
    <div class="right-warp">
        <!--logo填充-->
        <div class="logo">
            <img src="../img/logo1.jpg" style="width: 260px; height: 260px">
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
	function checkNull(){
		if($("#kid-comment").val()==""){
			return false;
		}
		return true;
	}
    function delKidCm(id){
    	var tipDelCm = confirm("你确定要删除此条回复？")
    	if(tipDelCm){
    		$.ajax({
                type:"post",
        		url:"method/delkidcm_action.php",
        		data:{id: id},
        		success:function(data){
        				alert(data)
        		}
            });
    		location.reload();
    	}
    }
    function comKidCm(id){
    	var tipComKidCm = confirm("你确定要投诉此条微博？")
    	if(tipComKidCm){
    		$.ajax({
                type:"post",
        		url:"method/complaintkidcm_action.php",
        		data:{id: id},
        		success:function(data){
        				alert(data)
        		}
            });
    	}
    }
</script>
</html>